package com.unify.python.analysis;

import com.alibaba.fastjson.JSONObject;
import com.unify.python.analysis.template.TemplateExtract;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Author: wchen
 * @Description:
 * @Date: Created in 2018-12-19 16:15
 * Copyright 本内容仅限于杭州阿拉丁信息科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
public class JsoupHtmlAnalysis extends AbsHtmlAnalysis {

    private static Logger logger = LoggerFactory.getLogger(JsoupHtmlAnalysis.class);

    private void analysisNode(Node node){


    }

    /**
     * 解析html
     *
     * @param htmlText
     * @return
     */
    @Override
    public JSONObject parseHtml(String htmlText) {
        TemplateExtract templateExtract = new TemplateExtract();
        String html = templateExtract.extractKeyWords();
        System.out.println("---" + html);
        Document document = Jsoup.parse(html);
        List<Node> nodes = document.childNodes();
        for(Node node : nodes){
            List<Node> chnodes1 = node.childNodes();

        }

//        Elements navElements = document.select("div.nav");
//        Element navElement = navElements.get(0);
//
//        Elements ulElements = navElement.select("ul");
//        Element ulElement = ulElements.get(0);
//
//        Elements liElements = ulElement.select("li");
//        for(int i=2; i<8; i++){
//            Element liElement = liElements.get(i);
//            String categoryName = liElement.text();
//
////            categoryName=text;refUrl=a.attr(href)
//            Elements aElements = liElement.select("a");
//            Element aElement = aElements.get(0);
//            String refUrl = aElement.attr("href");
//            System.out.println("categoryName :" + categoryName + " , refUrl = " + refUrl);
//        }

        return null;
    }

    public static void main(String[] args) {
        JsoupHtmlAnalysis analysis = new JsoupHtmlAnalysis();
        analysis.parseHtml(null);
    }
}
